home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IOInterface / Picture.dcl < prev    next >
Encoding:
Modula Definition  |  1997-04-23  |  8.8 KB  |  261 lines  |  [TEXT/3PRM]

  1. definition module Picture;
  2.  
  3. //    Version 0.8 to 1.0
  4.  
  5. //
  6. //    Drawing functions and other operations on Pictures. 
  7. //
  8.  
  9.  
  10. import    quickdraw;
  11. import    deltaFont;
  12.  
  13.  
  14. ::    *Picture;
  15.  
  16. ::    DrawFunction    :== Picture -> Picture;
  17.  
  18. //    The predefined figures that can be drawn:
  19.  
  20. ::    Point            :== (!Int, !Int);
  21. ::    Line            :== (!Point, !Point);
  22. ::    Curve            :== (!Oval, !Int, !Int);
  23. ::    Rectangle        :== (!Point, !Point);
  24. ::    RoundRectangle    :== (!Rectangle, !Int, !Int);
  25. ::    Oval            :== Rectangle;
  26. ::    Circle            :== (!Point, !Int);
  27. ::    Wedge            :== (!Oval, !Int, !Int);
  28. ::    Polygon            :== (!Point, !PolygonShape);
  29.  
  30. ::    PolygonShape    :== [Vector];
  31. ::    Vector            :== (!Int, !Int);
  32.  
  33.  
  34. //    The pen attributes which influence the way figures are drawn:
  35.  
  36. ::    PenSize        :== (!Int, !Int);
  37. ::    PenMode        =    CopyMode    | OrMode    | XorMode        | ClearMode   | HiliteMode
  38.                 |    NotCopyMode    | NotOrMode    | NotXorMode    | NotClearMode;
  39. ::    PenPattern    =  BlackPattern
  40.                 |    DkGreyPattern
  41.                 |    GreyPattern
  42.                 |    LtGreyPattern
  43.                 |    WhitePattern;
  44.  
  45. //    The colours:
  46.  
  47. ::    Colour    =    RGB Real Real Real
  48.             |    BlackColour    | RedColour
  49.             |    WhiteColour    | GreenColour
  50.             |    BlueColour    | YellowColour
  51.             |    CyanColour    | MagentaColour;
  52.  
  53. MinRGB    :== 0.0;
  54. MaxRGB    :== 1.0;
  55.  
  56.  
  57. //    Conversion of Toolbox to Picture and vise versa.
  58.  
  59. NewPicture        :: Picture;
  60. MakePicture        :: !Toolbox -> Picture;
  61. MakeMacPicture    :: !Picture -> Toolbox;
  62.  
  63.  
  64. //    Calculations with rects and regions.
  65.  
  66. Rect_in_region    :: !Rectangle !RgnHandle !Toolbox -> (!Bool, !Toolbox);
  67.  
  68.  
  69. //    Rules setting the attributes of a Picture:
  70.  
  71. /*    SetPenSize (w, h) sets the PenSize to w pixels wide and h pixels high.
  72.     SetPenMode sets the interference how new figures 'react' to drawn ones.
  73.     SetPenPattern sets the way new figures are drawn.
  74.     SetPenNormal sets the SetPenSize to (1,1), the PenMode to CopyMode and
  75.         the PenPattern to BlackPattern. */
  76.  
  77. SetPenSize            :: !PenSize            !Picture -> Picture;
  78. SetPenMode            :: !PenMode            !Picture -> Picture;
  79. SetPenPattern        :: !PenPattern        !Picture -> Picture;
  80. SetPenNormal        ::                    !Picture -> Picture;
  81.  
  82.  
  83. /*    Using colours:
  84.     There are basically two types of Colours: RGB and basic colours.
  85.         An RGB colour defines the amount of red (r), green (g) and blue (b)
  86.         in a certain colour by the tuple (r,g,b). These are REAL values and
  87.         each of them must be between MinRGB and MaxRGB (0.0 and 1.0).
  88.         The colour black is defined by (MinRGB, MinRGB, MinRGB) and white
  89.         by (MaxRGB, MaxRGB, MaxRGB).
  90.         Given a RGB colour, all amounts are adjusted between MinRGB and
  91.         MaxRGB.
  92.     Only FullColour windows can apply RGB colours. Applications that use
  93.     these windows may not run on all computers (e.g. Macintosh Plus).
  94.     A small set of basic colours is defined that can be used on all systems.
  95.     
  96.     SetPenColour    sets the colour of the pen.
  97.     SetBackColour    sets the background colour. */
  98.  
  99. SetPenColour        :: !Colour            !Picture -> Picture;
  100. SetBackColour        :: !Colour            !Picture -> Picture;
  101.  
  102.  
  103. /*    Using fonts:
  104.     The initial font of a Picture is 12 point Chicago in PlainStyle.
  105.     SetFont         sets a new complete Font in the Picture.
  106.     SetFontName     sets a new font without changing the style or size.
  107.     SetFontStyle sets a new style without changing font or size.
  108.     SetFontSize     sets a new size without changing font or style.
  109.                      The size is always adjusted between MinFontSize and
  110.                      MaxFontSize (see deltaFont.dcl). */
  111.  
  112. SetFont                :: !Font            !Picture -> Picture;
  113. SetFontName            :: !FontName        !Picture -> Picture;
  114. SetFontStyle        :: ![FontStyle]        !Picture -> Picture;
  115. SetFontSize            :: !FontSize        !Picture -> Picture;
  116.  
  117. PictureCharWidth    :: !Char            !Picture -> (!Int,        !Picture);
  118. PictureStringWidth    :: !{#Char}        !Picture -> (!Int,        !Picture);
  119. PictureFontMetrics    ::                    !Picture -> (!FontInfo, !Picture);
  120.  
  121.  
  122. //    Rules changing the position of the pen:
  123.  
  124. //    Absolute and relative pen move operations (without drawing).
  125.  
  126. MovePenTo            :: !Point            !Picture -> Picture;
  127. MovePen                :: !Vector            !Picture -> Picture;
  128.  
  129.  
  130. //    Absolute and relative pen move operations (with drawing).
  131.  
  132. LinePenTo            :: !Point              !Picture -> Picture;
  133. LinePen                :: !Vector            !Picture -> Picture;
  134.  
  135.  
  136. /*    DrawChar (DrawString) draws the character (string) in the current font.
  137.     The baseline of the characters is the y coordinate of the pen.
  138.     The new position of the pen is directly after the character (string)
  139.     including spacing.
  140. */
  141.  
  142. DrawChar            :: !Char            !Picture -> Picture;
  143. DrawString            :: !{#Char}        !Picture -> Picture;
  144.  
  145.  
  146. //    Rules not changing the position of the pen after drawing:
  147.  
  148. /*    Non plane figures:
  149.         Draw(C)Point    draws the pixel (in the given colour) in the Picture.
  150.         Draw(C)Line        draws the line  (in the given colour) in the Picture.
  151.         Draw(C)Curve    draws the curve (in the given colour) in the Picture.
  152.                         A Curve is part of an Oval o starting from angle a
  153.                         upto angle b (both of type INT in degrees modulo 360):
  154.                             (o, a, b).
  155.                         See Wedges for further information on the angles. */
  156.  
  157. DrawPoint            :: !Point            !Picture -> Picture;
  158. DrawLine            :: !Line            !Picture -> Picture;
  159. DrawCurve            :: !Curve            !Picture -> Picture;
  160.  
  161. DrawCPoint            :: !Point    !Colour !Picture -> Picture;
  162. DrawCLine            :: !Line    !Colour !Picture -> Picture;
  163. DrawCCurve            :: !Curve    !Colour !Picture -> Picture;
  164.  
  165.  
  166. /*    A Rectangle is defined by two of its diagonal corner Points (a, b)
  167.     with:    a: (a_x, a_y),
  168.             b: (b_x, b_y)
  169.     such that a_x <> b_x and a_y <> b_y.
  170.     In case either a_x = b_x or a_y = b_y, the Rectangle is empty.
  171.  
  172.     DrawRectangle    draws the edges of the rectangle.
  173.     FillRectangle    draws the edges and interior of the rectangle.
  174.     EraseRectangle    erases the edges and interior of the rectangle.
  175.     InvertRectangle    inverts the edges and interior of the rectangle.
  176.  
  177.     MoveRectangleTo    moves the contents of the rectangle to a new top corner.
  178.     MoveRectangle    moves the contents of the rectangle over the given vector.
  179.     CopyRectangleTo    copies the contents of the rectangle to a new top corner.
  180.     CopyRectangle    copies the contents of the rectangle over the given vector. */
  181.  
  182. DrawRectangle        :: !Rectangle !Picture -> Picture;
  183. FillRectangle        :: !Rectangle !Picture -> Picture;
  184. EraseRectangle        :: !Rectangle !Picture -> Picture;
  185. InvertRectangle        :: !Rectangle !Picture -> Picture;
  186.  
  187. MoveRectangleTo        :: !Rectangle !Point  !Picture -> Picture;
  188. MoveRectangle        :: !Rectangle !Vector !Picture -> Picture;
  189. CopyRectangleTo        :: !Rectangle !Point  !Picture -> Picture;
  190. CopyRectangle        :: !Rectangle !Vector !Picture -> Picture;
  191.  
  192.  
  193. /*    Rounded corner rectangles: a RoundRectangle with enclosing Rectangle
  194.     r and corner curvatures x and y is defined by the tuple (r, x, y).
  195.     x (y) defines the horizontal (vertical) diameter of the corner curves.
  196.     x (y) is always adjusted between 0 and the width (height) of r.
  197.     Note:    RoundRectangle (r, 0, 0) is the Rectangle r, 
  198.             RoundRectangle (r, w, h) is the Oval r if w and h are the width
  199.             and height of r.
  200. */
  201.  
  202. DrawRoundRectangle    :: !RoundRectangle    !Picture -> Picture;
  203. FillRoundRectangle    :: !RoundRectangle    !Picture -> Picture;
  204. EraseRoundRectangle    :: !RoundRectangle    !Picture -> Picture;
  205. InvertRoundRectangle:: !RoundRectangle    !Picture -> Picture;
  206.  
  207.  
  208. /*    Ovals: an Oval is defined by its enclosing Rectangle.
  209.     Note : the Oval of a square Rectangle is a Circle.
  210. */
  211.  
  212. DrawOval            :: !Oval            !Picture -> Picture;
  213. FillOval            :: !Oval            !Picture -> Picture;
  214. EraseOval            :: !Oval            !Picture -> Picture;
  215. InvertOval            :: !Oval            !Picture -> Picture;
  216.  
  217.  
  218. /*    Circles:    a Circle with center c (Point) and radius r (INT) is
  219.                 defined by the tuple (c, r). */
  220.  
  221. DrawCircle            :: !Circle            !Picture -> Picture;
  222. FillCircle            :: !Circle            !Picture -> Picture;
  223. EraseCircle            :: !Circle            !Picture -> Picture;
  224. InvertCircle        :: !Circle            !Picture -> Picture;
  225.  
  226.  
  227. /*    Wedges: a Wedge is a pie part of an Oval o starting from angle a
  228.     upto angle b (both of type INT in degrees modulo 360):
  229.         (o, a, b).
  230.     Angles are always taken counterclockwise, starting from 3 o'clock.
  231.     So angle 0 is at 3 o'clock, angle 90 (-270) at 12 o'clock,
  232.     angle 180 (-180) at 9 o'clock and angle 270 (-90) at 6 o'clock. */
  233.  
  234. DrawWedge            :: !Wedge            !Picture -> Picture;
  235. FillWedge            :: !Wedge            !Picture -> Picture;
  236. EraseWedge            :: !Wedge            !Picture -> Picture;
  237. InvertWedge            :: !Wedge            !Picture -> Picture;
  238.  
  239.  
  240. /*    Polygons: a Polygon is a figure drawn by a number of lines without
  241.     taking the pen of the Picture, starting from some Point p.
  242.     The PolygonShape s (a list [v1,...,vN] of Vectors) defines how the
  243.     Polygon is drawn:
  244.         MoveTo p, DrawLine from v1 upto vN, DrawLineTo p to close it.
  245.     So a Polygon with s [] is actually the Point p.
  246.     
  247.     ScalePolygon    by scale k sets shape [v1,...,vN] into [k*v1,...,k*vN].
  248.                         Negative, as well as 0 are valid scales.
  249.     MovePolygonTo    changes the starting point into the given Point and
  250.     MovePolygon        moves the starting point by the given Vector.
  251. */
  252.  
  253. DrawPolygon            :: !Polygon            !Picture -> Picture;
  254. FillPolygon            :: !Polygon            !Picture -> Picture;
  255. ErasePolygon        :: !Polygon            !Picture -> Picture;
  256. InvertPolygon        :: !Polygon            !Picture -> Picture;
  257.  
  258. ScalePolygon        :: !Int             !Polygon -> Polygon;
  259. MovePolygonTo        :: !Point            !Polygon -> Polygon;
  260. MovePolygon            :: !Vector            !Polygon -> Polygon;
  261.